package com.agritech.machine;

/**
 * 收割机类
 * 实现了农业机械抽象类，提供收割机特有的功能
 */
public class Harvester extends AgriculturalMachine {
    private int storageCapacity; // 存储容量(千克)
    private int currentStorage; // 当前存储量
    private double cuttingWidth; // 收割宽度(米)
    private double cuttingHeight; // 收割高度(厘米)

    public Harvester(String id) {
        super(id, "自动收割机");
        this.storageCapacity = 2000;
        this.currentStorage = 0;
        this.cuttingWidth = 5.0; // 默认收割宽度
        this.cuttingHeight = 15.0; // 默认收割高度
    }

    @Override
    public void start() {
        System.out.println(getType() + " [" + getId() + "] 启动中，检查系统...");
        if (currentStorage > storageCapacity * 0.8) {
            System.out.println("警告: 存储空间即将满，请及时卸载！");
        }
        updateStatus("工作中");
        System.out.println(getType() + " [" + getId() + "] 已启动，准备收割作业");
    }

    @Override
    public void stop() {
        System.out.println(getType() + " [" + getId() + "] 正在停止作业...");
        updateStatus("空闲");
        System.out.println(getType() + " [" + getId() + "] 已停止，收割作业结束");
    }

    @Override
    public void performTask(String taskDetails) {
        System.out.println(getType() + " [" + getId() + "] 正在执行收割任务: " + taskDetails);
        System.out.println("当前收割宽度: " + cuttingWidth + "米, 收割高度: " + cuttingHeight + "厘米");
        addHarvest(200); // 增加收获物
        consumeFuel(8.0); // 消耗燃油
    }

    /**
     * 调整收割宽度
     * @param width 新的收割宽度(米)
     */
    public void adjustCuttingWidth(double width) {
        System.out.println(getType() + " [" + getId() + "] 调整收割宽度从 " + this.cuttingWidth + "米 到 " + width + "米");
        this.cuttingWidth = width;
    }

    /**
     * 调整收割高度
     * @param height 新的收割高度(厘米)
     */
    public void adjustCuttingHeight(double height) {
        System.out.println(getType() + " [" + getId() + "] 调整收割高度从 " + this.cuttingHeight + "厘米 到 " + height + "厘米");
        this.cuttingHeight = height;
    }

    /**
     * 增加收获物
     * @param amount 增加的收获物量(千克)
     */
    private void addHarvest(int amount) {
        int newStorage = currentStorage + amount;
        if (newStorage > storageCapacity) {
            System.out.println("警告: " + getType() + " [" + getId() + "] 存储空间已满，无法继续收割！");
            this.currentStorage = storageCapacity;
        } else {
            this.currentStorage = newStorage;
            System.out.println(getType() + " [" + getId() + "] 已收获作物，当前存储量: " + currentStorage + "千克");
        }
    }

    /**
     * 卸载收获物
     */
    public void unloadHarvest() {
        System.out.println(getType() + " [" + getId() + "] 正在卸载收获物，卸载量: " + currentStorage + "千克");
        this.currentStorage = 0;
        System.out.println(getType() + " [" + getId() + "] 卸载完成，存储空间已清空");
    }

    /**
     * 获取当前存储量
     * @return 当前存储量(千克)
     */
    public int getCurrentStorage() {
        return currentStorage;
    }

    /**
     * 获取收割宽度
     * @return 收割宽度(米)
     */
    public double getCuttingWidth() {
        return cuttingWidth;
    }

    /**
     * 获取收割高度
     * @return 收割高度(厘米)
     */
    public double getCuttingHeight() {
        return cuttingHeight;
    }
}